<div class="layui-card">
	<div class="layui-card-header">
		<h2 class="header-title">反馈列表</h2>
		<span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>反馈列表</cite></a>
        </span>
	</div>
	<div class="layui-card-body">
		<div id="zby_t">
			<table class="layui-table" id="manage-table" lay-filter="maList"></table>
		</div>
		<div id="zby_u" style="display: none;">
			<form id="m-form" lay-filter="m-form" class="layui-form model-form zby_f">
				<input name="feedbackId" type="hidden" />
				<!--<input name="roleId" type="hidden" />-->
				<div class="layui-form-item">
					<label class="layui-form-label">用户昵称</label>
					<div class="layui-input-block">
						<p id="m_nc">莫玄</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">反馈时间</label>
					<div class="layui-input-block">
						<p id="m_sj">2017-5-21</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">手机号码</label>
					<div class="layui-input-block">
						<p id="m_hm">17600799312</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">微信号码</label>
					<div class="layui-input-block">
						<p id="m_wx">hello</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">手机型号</label>
					<div class="layui-input-block">
						<p id="m_xh">mi mix2</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">反馈内容</label>
					<div class="layui-input-block">
						<p id="m_nr">中毒不浅啊，兄dei</p>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">工单状态</label>
					<div class="layui-input-block">
						<input type="radio" name="sign" value="processed" title="已处理" checked="">
						<input type="radio" name="sign" value="unprocessed" title="未处理">
						<input type="radio" name="sign" value="inprocessed" title="处理中">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">受理人员 </label>
					<div class="layui-input-block">
						<select id="mkey" name="receiver"></select>
					</div>
				</div>

				<div class="layui-form-item model-form-footer">
					<button class="layui-btn layui-btn-primary" id="clearM" type="button">取消</button>
					<button class="layui-btn" lay-filter="m-form-submit" lay-submit>保存</button>
				</div>
			</form>
		</div>
	</div>
</div>

<script type="text/html" id="manageBar">
	<a class="layui-btn layui-btn-sm" lay-event="edit">查看</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="m-model">

</script>

<script>
	layui.use(['laydate', 'table', 'util', 'config', 'form'], function() {
		var laydate = layui.laydate;
		var table = layui.table;
		var config = layui.config;
		var util = layui.util;
		var form = layui.form;
		var com = layui.common;
		userfaceListV()

		function showFaceTable(tabledata) {
			table.render({
				elem: '#manage-table',
				id: 'manage-table',
				data: tabledata,
				page: true,
				response: {
					countName: 'data.total' //数据总数的字段名称，默认：count
				},
				cols: [
					[{
							checkbox: true
						},
						{
							field: 'headPortrait',
							title: '用户头像',
							style: 'height:70px;padding:0;',
							templet: function(b) {
								if(b.headPortrait == null || b.headPortrait == "") {
									var s = '<div><img src="assets/images/mrtx.png" width="50px"  height="50px" /></div>'
									return s
								} else {
									var s = '<div><img src="'
									s += b.headPortrait;
									s += '" width="50px"  height="50px" /></div>'
									return s
								}
							}
						},
						{
							field: 'userId',
							title: '用户ID'
						},
						{
							field: 'nickname',
							title: '用户昵称',
							templet: function(b) {
								if(b.nickname != null) {
									if(b.nickname.length == 1) {
										return b.nickname
									} else if(b.nickname.length == 2) {
										var a = b.nickname;
										a = a.substring(0, 1)
										return a + "*"
									} else {
										if(b.nickname != null) {
											var a = b.nickname;
											var x = a.substring(0, 1)
											var c = a.substring(b.nickname.length - 1, b.nickname.length)
											return x + "***" + c
										}
									}
								} else {
									return "未填写"
								}
							}
						},
						{
							field: 'addTime',
							title: '反馈时间',
							templet: function(d) {
								return d.addTime.substring(0, 10, '')
							}
						},
						{
							field: 'content',
							title: '反馈内容'
						},
						{
							field: 'sign',
							title: '工单状态',
							templet: function(d) {
								if(d.sign == "unprocessed") {
									return "未处理"
								}
								if(d.sign == "processed") {
									return "已处理"
								}
								if(d.sign == "inprocessed") {
									return "处理中"
								}
							}
						}, {
							field: 'receiver',
							title: '受理人员'
						},
						{
							field: 'caozuo',
							title: '操作',
							toolbar: "#manageBar"
						}
					]
				]
			});
		}

		function userfaceListV(quer) {
			$.ajax({
				type: "POST",
				url: manageListPath,
				data: {
					params: JSON.stringify({
						pageSize: 1000,
						pageNumber: 1,
					})
				},
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				beforeSend: function(request) {},
				success: function(data) {
					showFaceTable(data.rows);
				},
				error: function(result) {
					console.log(result);
					config.removeToken();
					location.replace('login.html');
				},
			});
		}

		form.on('submit(m-form-submit)', function(data) {
			//				jscz(roleUpdate, data.field);
			console.log(data.field)
			$.ajax({
				type: "POST",
				url: updateFeedbackInfo,
				traditional: true,

				data: {
					params: JSON.stringify(data.field)
				},
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				success: function(data) {
					userfaceListV()
					gb()
					layer.closeAll('loading');
					layer.msg(data.msg, {
						icon: 1
					});
				},
				error: function(result) {
					console.log(result);
				},
			});
			return false;
		});

		var showEditModel = function(datas) {
			$.ajax({
				type: "POST",
				url: path + '/sys/user/list1',
				data: {
					sortOrder: "asc",
					pageSize: 1000,
					pageNumber: 1,
					roleName: ''

				},
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				beforeSend: function(request) {},
				success: function(data) {
					console.log(data)
					$('#m-form')[0].reset();
					$('#m-form').attr('method', 'GET');
					var select = document.getElementById("mkey")
					select.options.add(new Option("请选择", ''))
					for(var i = 0; i < data.rows.length; i++) {
						if(data.rows[i].orgId == 1) {
							select.options.add(new Option(data.rows[i].username, data.rows[i].username));
						}
					}
					form.render(select);

					$("#m_nc").html('');
					$("#m_sj").html('');
					$("#m_hm").html('');
					$("#m_wx").html('');
					$("#m_xh").html('');
					$("#m_nr").html('');

					$("#m_nc").html(datas.nickname);
					$("#m_sj").html(datas.addTime);
					$("#m_hm").html(datas.username);
					$("#m_wx").html(datas.wxId);
					$("#m_xh").html(datas.phoneModel);
					$("#m_nr").html(datas.content);

					//					$(select).val(datas.orgId);
					form.val('m-form', datas);
					$('#m-form').attr('method', 'GET');
				},
				beforeSend: function() {},
				complete: function() {},
				error: function(result) {
					console.log(result);
				},
			})

		};

		$("#clearM").click(function() {
			gb()
		})

		function gb() {
			$("#m_nc").html('');
			$("#m_sj").html('');
			$("#m_hm").html('');
			$("#m_wx").html('');
			$("#m_xh").html('');
			$("#m_nr").html('');
			$('#zby_t').css("display", "block")
			$('#zby_u').css("display", "none")
		}

		table.on('tool(maList)', function(obj) {
			var data = obj.data;
			if(obj.event === 'edit') {
				$('#zby_u').css("display", "block")
				$('#zby_t').css("display", "none")
				showEditModel(data);
			}
		});

	});
</script>